package com.yj.web;


import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.yj.entity.Users;
import com.yj.service.IUsersService;
import com.yj.vo.JsonResult;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 *  前端控制器
 * </p>
 *用户在未登陆下只能进行登录注册操作
 * @author yj
 * @since 2020-08-24
 */
@RestController
//@RequestMapping("/users")
public class UsersController {

	@Autowired
	IUsersService users;
	
	//注册
	@PostMapping("/zhuce")
	public JsonResult zhuCe(Users user) {
		return users.zuCe(user);
	}
	
	//登录
	@PostMapping("/login")
	public JsonResult login(@Param(value = "uemail") String uemail,@Param(value = "password") String pass,HttpSession session) {
		JsonResult jsonResult=users.login(uemail, pass, session);
		return jsonResult;
	}
	
	//更新用户信息
	@PostMapping("/users/updata")
	public JsonResult updata(Users user) {
		return users.updataUser(user);
	}
	
	//获取当前用户信息
	@PostMapping("/users/getinfo")
	public JsonResult getSession(HttpSession session) {
		JsonResult ret = null;
		Users user =  (Users)session.getAttribute("usersession");
		ret = new JsonResult(true, "成功");
		ret.setData("user", user);
		return ret;
	}
	
	//上传头像
	@PostMapping("/users/imgupload")
	public JsonResult upLoad(int uid,@RequestParam("file") MultipartFile file) {
//		List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
		return users.upLoadImg(uid, file);
	}
	
}
